﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;

namespace TTCaller
{

    public partial class MainScreenPanel : UserControl
    {



        public MainScreenPanel()
        {
            InitializeComponent();
            this.timer_MainScreen.Enabled = true;

            
        }

        DateTime m_dtBox = System.DateTime.Now;

        public void initial()
        {
            this.label_Addr.Text = Form_Main.Main.m_strAddr;
            this.label_Title.Text = StoreData.getInstance().TTTitle;

            this.label_Tel.Text = "客服專線: " + StoreData.getInstance().TTTEL;

            this.panel_Msg.Visible = false;
        }


        bool m_bMsgShow = false;
        DateTime m_dtMsgShow = System.DateTime.Now;


        public void ShowMsgPanel(string arg_strMsg, int arg_nSecs, bool arg_bShowButton)
        {
            this.label_Msg.Text = arg_strMsg;
            this.label_Msg.Tag = arg_strMsg;
            m_dtMsgShow = System.DateTime.Now.AddSeconds(arg_nSecs);
            m_bMsgShow = true;
            this.panel_Msg.Visible = true;

        }

        private void button_F1_Click(object sender, EventArgs e)
        {
            Form_Main.Main.ChangeToPrepareCallTaxi();
        }

        public void checkButtonDT()
        {

            if (!button_F1.Enabled && m_dtDisableButtonOneSec < System.DateTime.Now && !Form_Main.Main.IsSendAndWait) 
            {
                button_F1.Enabled = true;
                //if(button_F2.Text != "離開")
                    button_F2.Enabled = true;
                //if(button_F3.Text != "未見" )
                    button_F3.Enabled = true;

            }

        }

        private void timer_MainScreen_Tick(object sender, EventArgs e)
        {

            checkButtonDT();


            if (m_bMsgShow && m_dtMsgShow < System.DateTime.Now)
            {
                m_bMsgShow = false;
                this.panel_Msg.Visible = false;
            }
            if (m_bMsgShow)
            {
                SoundManager.getInstance().playJobGot();
            }


        }



 


        DateTime m_dtDisableButtonOneSec = System.DateTime.Now;
        public void disableButtonOneSec()
        {
            m_dtDisableButtonOneSec = System.DateTime.Now.AddMilliseconds(500);
            //this.button_F1.Enabled = false;
            //this.button_F2.Enabled = false;
            //this.button_F3.Enabled = false;
        }


        private void button_F2_Click(object sender, EventArgs e)
        {

        }

        private void button_F3_Click(object sender, EventArgs e)
        {
            Form_Main.Main.ChangeToMsgList(MsgType.Dispatch);
        }

        private void button_MsgOK_Click(object sender, EventArgs e)
        {
            m_bMsgShow = false;
            this.panel_Msg.Visible = false;
        }

        private void button_Sound_Click(object sender, EventArgs e)
        {
            Form_Main.Main.ChangeToSysConfig();
        }

        private void button_Msg_Click(object sender, EventArgs e)
        {
            Form_Main.Main.ChangeToMsgList(MsgType.Msg);

        }

    }
}
